﻿
using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 膨胀
    /// </summary>
    [Filter("膨胀", FilterType.Algorithm)]
    public class AlgorithmDilate : FilterBase
    {
        /// <summary>
        /// 锚点
        /// </summary>
        [InputParameter("锚点")]
        public CVPoint Anchor { get; set; } = new CVPoint() { X=-1,Y=-1};
        /// <summary>
        /// 膨胀核大小
        /// </summary>
        [InputParameter("核大小")]
        public CVSize KernalSize { get; set; } = new CVSize { Height = 15, Width = 15 };
        /// <summary>
        /// 迭代次数
        /// </summary>
        [InputParameter("迭代次数")]
        public int Iterations { get; set; } = 1;
        /// <summary>
        /// 边界类型
        /// </summary>
        [InputParameter("边界类型")]
        public BorderTypes BorderTypes { get; set; } = BorderTypes.Reflect101;
        /// <summary>
        /// 颜色
        /// </summary>
        [InputParameter("颜色")]
        public Scalar Color { get; set; }
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
          var element =  Cv2.GetStructuringElement(MorphShapes.Rect, KernalSize);
            Mat outMat = new Mat();
            Cv2.Dilate(mat, outMat, element, Anchor, Iterations, BorderTypes, Color);
            return ResultData<Mat>.Accept(TextResource.filter_action_complete, outMat);
        }
    }

}
